package com.dt76.smallloanbackenduser.controller.jh;
import com.dt76.smallloanbackenduser.pojo.jh.DataTemplate;

import com.dt76.smallloanbackenduser.pojo.jh.SortRegisterUserInfo;
import com.dt76.smallloanbackenduser.remote.jh.UserstatisticsRemote;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@RequestMapping("/jh")
public class UserstatisticsController {
    @Autowired
    private UserstatisticsRemote userstatisticsRemote;

    @GetMapping("/toUserstatistics")
    public String toUserstatistics() {
        return "pages/jiang/Userstatistics";
    }

    /*@GetMapping("/qryAll")
    @ResponseBody
    public int[] Userrr(Model model) {
        System.out.println("调用成功");
        int[] testData = {700, 500, 50, 400, 285, 930, 185, 265, 542, 1102, 987, 985, 500};
        return testData;
    }*/
    /*@GetMapping("/qryAll")
    @ResponseBody
    public int[] Userrr(Model model) {
        List<DataTemplate> dataTemplates = userstatisticsRemote.qryAll();
        int[] registerNums = new int[dataTemplates.size()];
        for(int i = 0; i < dataTemplates.size(); i++){
            registerNums[i] = Integer.valueOf(dataTemplates.get(i).getA_count());
        }
        System.out.println("调用成功q");
        for (int registerNum : registerNums) {
            System.out.println(registerNum);
        }
        return registerNums;
    }*/
    @GetMapping("/qryAll")
    @ResponseBody
    public int[] Userrr(Model model) {
        Map<String, List<DataTemplate>> map = userstatisticsRemote.qryAll();
        List<DataTemplate> list = map.get("list");
        int[] registerNums = new int[list.size()];
        for (int i = 0; i < list.size(); i++) {
            registerNums[i] = Integer.valueOf(list.get(i).getA_count());
        }
        System.out.println("调用成功q");
        for (int registerNum : registerNums) {
            System.out.println(registerNum);
        }
        return registerNums;
    }

    /*@GetMapping("/qryAllTwo")
    @ResponseBody
    public Map<String, List<DataTemplate>> UserTwo(Model model) {
        Map<String, List<DataTemplate>> listMap = userstatisticsRemote.qryAll();
        List<DataTemplate> list2 = listMap.get("list2");
        List<DataTemplate> list3 = listMap.get("list3");
        int[] ConfirmIDs = new int[list2.size()];
        int[]  Numbers = new int[list3.size()];
        for (int i = 0;i<list2.size();i++){
            ConfirmIDs[i] = Integer.valueOf(list2.get(i).getA_count());
        }
        for (int i = 0;i<list3.size();i++){
            Numbers[i] = Integer.valueOf(list3.get(i).getA_count());
        }
        System.out.println("调用成功");
         for(int ConfirmID : ConfirmIDs){
             System.out.println(ConfirmID);
         }
        for(int Number : Numbers){
            System.out.println(Number);
        }
        *//*Map<String, Object> map = new HashMap<>();
        map.put("list2",new SortRegisterUserInfo("实名认证用户数",list2);
        map.put("list3",new SortRegisterUserInfo("绑卡用户数",list3));*//*
        return listMap;

    }*/

    @GetMapping("/qryAllTwo")
    @ResponseBody
    public Map<String, Object> UserTwo(Model model) {
        Map<String, List<DataTemplate>> listMap = userstatisticsRemote.qryAll();
        List<DataTemplate> list2 = listMap.get("list2");
        double[] ConfirmIDs = new double[list2.size()];
        for (int j = 0; j < list2.size(); j++) {
            ConfirmIDs[j] = Integer.valueOf(list2.get(j).getA_count());
        }
        List<DataTemplate> list3 = listMap.get("list3");
        double[] Nunbers = new double[list3.size()];
        for (int j = 0; j < list3.size(); j++) {
            Nunbers[j] = Integer.valueOf(list3.get(j).getA_count());
        }
        System.out.println("调用成功");
        double[] serieA = ConfirmIDs;
        double[] serieB = Nunbers;
        Map<String, Object> map = new HashMap<>();
        map.put("serieA", new SortRegisterUserInfo("实名认证用户数", serieA));
        map.put("serieB", new SortRegisterUserInfo("绑卡用户数", serieB));
        return map;
    }

    @GetMapping("/qryAllthree")
    @ResponseBody
    public double[] meony(Model model) {
        Map<String, List<DataTemplate>> mapAll = userstatisticsRemote.qryAll();
        List<DataTemplate> list4 = mapAll.get("list4");
        double[] DataTemplates = new double[list4.size()];
        for (int t = 0; t < list4.size(); t++) {
            DataTemplates[t] = Integer.valueOf(list4.get(t).getA_count());
        }
        System.out.println("调用成功q");
        return DataTemplates;
    }
}
